package com.srwl.mytx.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.srwl.mytx.Constant;
import com.srwl.mytx.R;

public class SelectTopicTypePopupWindow extends PopupWindow implements View.OnClickListener {

    private SelectTopicTypeListener listener;

    public SelectTopicTypePopupWindow(Context context) {
        super(context);

        initView(context);
    }
    public SelectTopicTypePopupWindow(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SelectTopicTypePopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.select_topic_type_menu_layout, null);
        view.findViewById(R.id.rl_expose).setOnClickListener(this);
        view.findViewById(R.id.rl_lost_people).setOnClickListener(this);
        view.findViewById(R.id.rl_lost_thing).setOnClickListener(this);
        view.findViewById(R.id.rl_found).setOnClickListener(this);
        view.findViewById(R.id.rl_gift).setOnClickListener(this);
        view.findViewById(R.id.rl_show).setOnClickListener(this);
        view.findViewById(R.id.rl_goods).setOnClickListener(this);
        view.findViewById(R.id.rl_auction).setOnClickListener(this);
        //设置ChooseRecordPopupWindow的View
        this.setContentView(view);
        //设置ChooseRecordPopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置ChooseRecordPopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置ChooseRecordPopupWindow弹出窗体可点击
        this.setFocusable(true);
        // 设置弹出窗体的背景
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }


    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.rl_expose:
                listener.onSelectTopicType(Constant.TOPIC_TYPE_EXPOSE);
                break;
            case R.id.rl_lost_people:
                listener.onSelectTopicType(Constant.TOPIC_TYPE_LOST_PEOPLE);
                break;
            case R.id.rl_lost_thing:
                listener.onSelectTopicType(Constant.TOPIC_TYPE_REWARD);
                break;
            case R.id.rl_found:
                listener.onSelectTopicType(Constant.TOPIC_TYPE_FOUND);
                break;
            case R.id.rl_gift:
                listener.onSelectTopicType(Constant.TOPIC_TYPE_GIFT);
                break;
            case R.id.rl_show:
                listener.onSelectTopicType(Constant.TOPIC_TYPE_SHOW);
                break;
            case R.id.rl_goods:
                listener.onSelectTopicType(Constant.TOPIC_TYPE_GOODS);
                break;
            case R.id.rl_auction:
                listener.onSelectTopicType(Constant.TOPIC_TYPE_AUCTION);
                break;
        }
    }

    public void setSelectTopicTypeListener(SelectTopicTypeListener listener) {
        this.listener = listener;
    }

    public interface SelectTopicTypeListener {

        void onSelectTopicType(int topicType);
    }

}
